<?php
namespace App\Http\Controllers\Admin\Picture;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class IndexController extends Controller
{	
	public $assign = [];
	public $table = 'picture';
	public $model = '';
	public $m = '';

	/**
	 * /	构造函数
	 * @return [type] [description]
	 */
	public function __construct() 
	{
       $this->model = new \App\Model\M();
       $this->m = new \App\Model\admin\Picture();
       return true;
	}

	/**
	 * /	品牌列表
	 * @return [type] [description]
	 */
	public function index()
	{
		if (empty($_COOKIE['TestCookie'])) {
            return redirect($_SESSION['web']['houtai']."login");
        }
        if (!empty($_GET['id'])) {
        	$_SESSION['admin']['data']['chanpin']['id'] = $_GET['id'];
        }
        $id = $_SESSION['admin']['data']['chanpin']['id'];
        $info = $this->m->get($id);
        $this ->assign['info'] = $info;
		return view('Admin.Picture.index',$this->assign);
	}

	/**
	 * /	新增
	 * @return [type] [description]
	 */
	public function add()
	{
		if (empty($_COOKIE['TestCookie'])) {
            return redirect($_SESSION['web']['houtai']."login");
        }
		return view('Admin.Picture.add',$this->assign);
	}

	/**
	 * /	确认新增
	 * @return [type] [description]
	 */
	public function doadd()
	{
		if (empty($_COOKIE['TestCookie'])) {
            return redirect($_SESSION['web']['houtai']."login");
        }
        if (!empty($_FILES['icon']['name'])) {
        	$icon = $this->model->uploads('icon');
        }else{
        	$icon = '';
        }
        $result = $this->m->add($_POST['main'],$_POST['status'],$icon);
        return redirect($_SESSION['web']['houtai'].'show_picture?id='.$_SESSION['admin']['data']['chanpin']['id']);
	}

	/**
	 * /	编辑
	 * @return [type] [description]
	 */
	public function edit()
	{
		if (empty($_COOKIE['TestCookie'])) {
            return redirect($_SESSION['web']['houtai']."login");
        }
        $info = $this->model->find($this->table,'id',$_GET['id']);
        $this ->assign['info'] = $info;
		return view('Admin.Picture.edit',$this->assign);
	}

	/**
	 * /	确认编辑
	 * @return [type] [description]
	 */
	public function doedit()
	{
		if (empty($_COOKIE['TestCookie'])) {
            return redirect($_SESSION['web']['houtai']."login");
        }
        if (!empty($_FILES['icon']['name'])) {
        	$icon = $this->model->uploads('icon');
        }else{
        	$icon = $this->model->find($this->table,'id',$_POST['id'])->icon;
        }
        if ($_POST['shanchu'] == 'shan') {
        	$icon = '';
        }
        $result = $this->m->update_list($_POST['id'],$_POST['main'],$_POST['status'],$icon);
        return redirect($_SESSION['web']['houtai'].'show_picture?id='.$_SESSION['admin']['data']['chanpin']['id']);
	}

//ajax----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	
	/**
	 * /	ajax 批量下架
	 * @return [type] [description]
	 */
	public function xia()
	{
		$reslut = $this->model->xia($this->table,$_POST['id']);
	}

	/**
	 * /	ajax 批量显示
	 * @return [type] [description]
	 */
	public function shang()
	{
		$reslut = $this->model->shang($this->table,$_POST['id']);
	}

	/**
	 * /	单个显示下架
	 * @return [type] [description]
	 */
	public function shang_xia()
	{
		$reslut = $this->model->shang_xia($this->table,$_POST['id']);
	}

	/**
	 * /	单个删除
	 * @return [type] [description]
	 */
	public function del_one()
	{
		$reslut = $this->model->del_one($this->table,$_POST['id']);
	}

	/**
	 * /	批量删除
	 * @return [type] [description]
	 */
	public function del()
	{
		$reslut = $this->model->del($this->table,$_POST['id']);
	}

}


















